package edu.ccut.saturn.studio.logic.model.commands;

import org.eclipse.gef.commands.Command;
import org.eclipse.jface.dialogs.Dialog;

import edu.ccut.saturn.studio.logic.model.Connection;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnDecisionNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnSwichNode;

public class OpenConnectionCommand extends Command {
	private Dialog dialog;
	private Connection shape;

	public OpenConnectionCommand(Dialog dialog, Connection shape) {
		this.dialog = dialog;
		this.shape = shape;
	}

	public void execute() {
		dialog.open();
	}

	public boolean canExecute() {

		if (dialog != null
				&& shape != null
				&& (shape.getLineStyle() == 1 || (shape.getLineStyle() == 2 && shape
						.getSource() instanceof SaturnDecisionNode))
				&& ((shape.getSource() instanceof SaturnSwichNode) || (shape
						.getSource() instanceof SaturnDecisionNode)))
			return true;
		else
			return false;
	}

}
